#include "../source/server.hpp"
#include <atomic>
#include <iostream>
using namespace std;
atomic<int> cnt;
void TestSocketClient()
{
    // while(true)
    // for(int i=0;i<5;++i)
    // {
        Socket client;
        client.CreateClient(8000, "127.0.0.1");
        // sleep(20);
        char buffer[1024] = {0};
        std::string message = "Hello, Server!\n";
        client.Send(message.c_str(), message.size());
        client.Recv(buffer, sizeof(buffer) - 1);
        DEBUG_LOG("Received from server: %s", buffer);
        cnt++;
        sleep(1);
    // }
    // while(true);
    sleep(5);
}
int main()
{
    int n = 1000;
    vector<thread> clients(n);
    for (int i = 0; i < n; ++i)
    {
        clients[i] = thread(TestSocketClient);
    }
    for(int i = 0; i < n; ++i)
    {
        clients[i].join();
    }
    cout << "Total clients connected: " << cnt.load() << endl;
    return 0;
}